package com.java.redis.impl;

import com.alibaba.fastjson.JSON;
import com.java.entity.PsUser;
import com.java.redis.RedisLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author caiyuan
 * @version 1.0
 * @Date 2020/6/11 18:36 Dream-Seeker
 * @Description
 */
@Component
public class RedisLoginImpl implements RedisLogin {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void setAllUser(List<PsUser> listUser) {
        redisTemplate.opsForValue().set("allUser", JSON.toJSONString(listUser));
    }

    @Override
    public List<PsUser> getAllUser() {
        Object users = redisTemplate.opsForValue().get("allUser");
        List<PsUser> userListJson = null;
        if (users != null) {
            userListJson = JSON.parseArray(users.toString(), PsUser.class);
        }
        return userListJson;
    }
}
